const fs = require("fs");
const path = require("path");

var pathFrom = path.join(__dirname, "/1.txt");
var pathTo = path.join(__dirname, "/8.txt");

var readStream = fs.createReadStream(pathFrom);
var writeable = fs.createWriteStream(pathTo);

readStream.pipe(writeable);

writeStream.on("close", ()=>{
    var fileObj = fs.statSync(pathFrom); // fs.statSync用于返回有关给定文件路径的信息
    //同步版 fs.statSync(path) 只接收path一个路径变量
    //异步版 fs.stat(path,callback) ，path变量 和一个回调函数

    fs.chmodSync(pathTo, fileObj.mode) //赋予文件权限
})